﻿@using BBICMS.Infrastructure
@model BBICMS.Model.ViewModel.Back.CarouselListVM

@{
    ViewBag.Title = "首页轮播";
    ViewBag.PageTitle = ViewBag.Title + "_组件";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}


<div class="main-content">
    <div class="panel panel-default">
        <div class="panel-heading">
           <span class="glyphicon glyphicon-picture"></span> @ViewBag.Title        
        </div>       

        <div class="panel-body">
            <div class="text-right">
                <a class="btn btn-primary" href="@Url.Action("AddCarousel")"><i class="glyphicon glyphicon-plus"></i> 添加图片</a>
            </div>
        </div>


            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>
                                缩略图
                            </th>
                            <th>
                                排序
                            </th>
                            <th>
                                主题
                            </th>
                            <th>
                                网站链接
                            </th>
                            <th>
                                创建日期
                            </th>
                            <th>
                                操作
                            </th>
                        </tr>
                    </thead>

                    <tbody>
                        @foreach (var Carousel in Model.Carousels)
                        {
                            <tr class="first">
                                <td>
                                    <img class="img-thumbnail" src="@string.Format("{0}?w=90&h=30&mode=crop", Carousel.ImageUrl)" />
                                </td>
                                <td>@Carousel.Importance</td>
                                <td>@Carousel.Title</td>
                                <td><a href="@Carousel.WebLink" target="_blank">@Carousel.WebLink</a></td>
                                <td>@Carousel.AddedDate</td>
                                <td>
                                    <a href="Carousel/EditCarousel/@Carousel.Id" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                                    <a href="Carousel/DeleteCarousel/@Carousel.Id" class="btn btn-xs btn-danger delete-carousel"><i class="glyphicon glyphicon-trash"></i></a>
                                </td>
                            </tr>
                        }

                    </tbody>

                </table>



          
        </div>

        <div class="panel-footer">
            <ul class="pagination">
                @Html.PageLinks(Model.PagingInfo, x => Url.Action("Articles", new { Page = x }))
            </ul>
        </div>
    </div>
</div>
<!-- end main container -->
@section footer {
    <script>
        $(function () {
            //删除数据
            $('.delete-carousel').click(function (e) {
                var url = $(this).attr('href');
                var that = $(this);
               // console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data) {
                            toastr.success('图片已删除成功！', '删除图片');
                            that.closest('tr').remove();
                        } else {
                            toastr.error('图片删除失败！', '删除图片');
                        }
                    },
                    error: function (xhr) {
                        toastr.error('图片删除失败！', '删除图片');
                    }
                });

                e.preventDefault();
            })

        });
    </script>

}